<?php 
namespace Core\Application;

/**
 * Represents a route or a matched route. This class cannot be inherits.
 * @namespace Core\Application
 * @author Raphael DE FREITAS (RaphyTheGeek@gmail.com)
 * @version 1.0
 *
 */
final class Route
{
	/**
	 * Contains the URI of this route.
	 * @var string
	 * @see getUri
	 */
	protected $_Uri = null;
	
	/**
	 * Contains the module name of this route.
	 * @var string
	 * @see getModule
	 */
	protected $_Module = null;
	
	/**
	 * Contains the controller name of this route.
	 * @var string
	 * @see getController
	 */
	protected $_Controller = null;
	
	/**
	 * Contains the action name of this route.
	 * @var string
	 * @see getAction
	 */
	protected $_Action = null;
	
	/**
	 * Contains the variables of this route.
	 * @var array
	 * @see getVars
	 */
	protected $_Vars = array();
	
	/**
	 * Initializes a new instance of the Route class with specified parameters.
	 * @param string $uri The URI which match to this route.
	 * @param string $module The name of the module to which this road is.
	 * @param string $controller The name of the controller to which this road is.
	 * @param string $action The name of the action to which this road is.
	 * @param array $vars Variables name in the URI.
	 */
	public function __construct($uri, $module, $controller, $action, $vars = array()) {
		$this->_Uri = $uri;
		$this->_Module = $module;
		$this->_Controller = $controller;
		$this->_Action = $action;
		$this->_Vars = $vars;
	}
	
	/**
	 * Obtains the URI corresponding to this route.
	 * @return string The URI corresponding to this route.
	 */
	public function getUri() {
		return $this->_Uri;
	}
	
	/**
	 * Obtains the module name corresponding to this route.
	 * @return string The module name corresponding to this route.
	 */
	public function getModule() {
		return $this->_Module;
	}
	
	/**
	 * Obtains the controller name corresponding to this route.
	 * @return string The controller name corresponding to this route.
	 */
	public function getController() {
		return $this->_Controller;
	}
	
	/**
	 * Obtains the action name corresponding to this route.
	 * @return string The action name corresponding to this route.
	 */
	public function getAction() {
		return $this->_Action;
	}
	
	public function hasVars() {
		return !empty($this->_Vars);
	}
	
	public function setVars($vars) {
		$this->_Vars = $vars;
	}
	
	/**
	 * Obtains the variables corresponding to this route.
	 * @return string The variables corresponding to this route.
	 */
	public function getVars() {
		return $this->_Vars;
	}
	
	/**
	 * Obtains the matches result if the URI specfiec correspond to this route.
	 * @param string $uri The URI to check it.
	 * @return array if this route matches to the URI; otherwise, FALSE.
	 */
	public function match($url) {
		if (preg_match('`^'.$this->_Uri.'$`', $url, $matches))
			return $matches;
		else
			return false;
	}
}
?>